package com.water.wfo.user.controller;

import com.water.wfo.component.api.entity.response.BasicResponse;
import com.water.wfo.component.constant.Constants;
import com.water.wfo.sys.pojo.entity.BulletinEntiy;
import com.water.wfo.sys.pojo.request.DataDictionaryRequest;
import com.water.wfo.sys.pojo.response.ParameterResponse;
import com.water.wfo.user.ability.BulletinAbility;
import com.water.wfo.user.api.BulletinApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * packageName com.water.wfo.user.controller
 *
 * @author
 * @className DataDictionaryController(处以class为网)
 * @date 2024/11/29
 * @description T0D0
 */
@Slf4j
@RestController
public class BulletinController implements BulletinApi {

    @Autowired
    private BulletinAbility bulletinAbility;
    @Override
    public BasicResponse<ParameterResponse> queryBulletinList(DataDictionaryRequest request) {
        BasicResponse<ParameterResponse> basicResponse = new BasicResponse<>();
        if(null == request){
            return basicResponse.buildFail("入参为空");
        }
        try {
            ParameterResponse response = bulletinAbility.queryBulletinListBy(request);
            return basicResponse.buildSuccess(response);
        } catch (Exception e) {
            log.error("查询角色集合异常:",e);
            return  basicResponse.buildFail("查询客户集合异常");
        }
    }

    @Override
    public BasicResponse<String> addBulletinInfo(@RequestBody BulletinEntiy entity) {
        BasicResponse<String> basicResponse = new BasicResponse<>();
        if(null == entity){
            return basicResponse.buildFail("入参为空");
        }
        try {
            entity.setActive(Constants.ACTIVE);
            bulletinAbility.insert(entity);
            return basicResponse.buildSuccess();
        } catch (Exception e) {
            log.error("新增菜单异常:",e);
            return  basicResponse.buildFail(e.getMessage());
        }
    }

    @Override
    public BasicResponse<String> editeInfo(@RequestBody BulletinEntiy dictionaryEntity) {
        BasicResponse<String> basicResponse = new BasicResponse<>();
        if(null == dictionaryEntity){
            return basicResponse.buildFail("入参为空");
        }
        try {
            bulletinAbility.update(dictionaryEntity);
            return basicResponse.buildSuccess();
        } catch (Exception e) {
            log.error("新增数据字典异常:",e);
            return  basicResponse.buildFail(e.getMessage());
        }
    }

    @Override
    public BasicResponse<String> batchDeletesData(@RequestBody Map<String, Object> map) {
        BasicResponse<String> basicResponse = new BasicResponse<>();
        if(null == map){
            return basicResponse.buildFail("入参为空");
        }
        try {
            List ids = (List) map.get("ids");
            bulletinAbility.deleteBatchByIds(ids);
            return basicResponse.buildSuccess();
        } catch (Exception e) {
            log.error("新增菜单异常:",e);
            return  basicResponse.buildFail(e.getMessage());
        }
    }
}
